using UnityEngine;
using UnityEngine.UI;

public class AudioManager : MonoBehaviour
{
    public static AudioManager instance;
    public SoundData soundData;
    public AudioSource audioSource;
    public AudioClip audioClip;

    private void Awake()
    {
        instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        audioSource = GetComponent<AudioSource>();
        Button[] buttons = Resources.FindObjectsOfTypeAll<Button>();
        foreach (Button button in buttons)
        {
            button.onClick.AddListener(MenuBtnClick);
        }
    }

    private void MenuBtnClick()
    {
        PlayerMenuAudio();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void PlayerPieceAudio()
    {
        AudioClip audioClip1 = soundData.pieceClips[Random.Range(0, soundData.pieceClips.Length)];
        audioSource.PlayOneShot(audioClip1);
    }
    public void PlayerMenuAudio()
    {
        AudioClip audioClip1 = soundData.menuClips[Random.Range(0, soundData.menuClips.Length)];
        audioSource.PlayOneShot(audioClip1);
    }
}
